﻿using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebAsp0001.Controllers.Demain
{
    public class DbInit
    {
        public static void Init()
        {
            using(var db = new AdminDbController())
            {
                db.Database.EnsureCreated();

                var temple = db.Brands.Any();

                if (!temple)
                {
                    var Brand1 = new Brand
                    {
                        BrandName = "Apple",
                        Description = "牛顿的苹果"
                    };

                    db.Brands.Add(Brand1);
                    db.SaveChanges();


                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName = "Apple X 原谅绿",
                        ShortDesc="这是一个简介描述",
                        FullDesc="这是一个详情",
                        BrandId=Brand1.Id
                    },
                    new Product
                    {
                        ProductName = "Apple X 雪崩红",
                        ShortDesc="shift",
                        FullDesc="Fuck",
                        BrandId=Brand1.Id
                    }
                    });

                    db.SaveChanges();
                }

              

            }
        }
    }
}
